//
// Created by Sugars Mac on 2020/5/26.
//

#include "../relation.h"
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>

void testForRelation(){
    int Tom = 1, Ben = 2, Jenny = 3;
    relationMap * head = (relationMap*)malloc(sizeof(relationMap));
    head->next = NULL;
    relationMap *r1 = buildRelation(Tom, Ben);
    relationMap *r2 = buildRelation(Ben, Jenny);
    relationMap *rfake = buildRelation(8, 9);
    addRelation(head, r1);
    addRelation(head, r2);
    showRelation(head);
    printf("find 1->2 : %d, find 8->9 :%d\n", findRelation(head, r1), findRelation(head, rfake));
    addRelation(head, rfake);
    showRelation(head);
    printf("delete the 1->2: \n");
    deleteRelation(head, r1);
    showRelation(head);
    deleteAllRela(head);
}

void testUserTable(){
    TableList_t * head = (TableList_t *)malloc(sizeof(TableList_t));
    head->data = NULL;
    head->next = NULL;
    readFromFile(head);
    showTable(head);

    UserTable_t * u = findUserByName(head, "Victor");
    if (u != NULL)
        printf("find: %s", u->username);


//    UserTable_t * u1 = (UserTable_t*)malloc(sizeof(UserTable_t));
//    memset(u1->username, 0, sizeof(u1->username));
//    strcpy(u1->username, "Jenny");
//    memset(u1->password, 0, sizeof(u1->password));
//    strcpy(u1->password, "988");
//    insertTable(head, u1);
//    showTable(head);

//    writeToFile(head);
    destroyTable(head);
}

int main(){
    // testUserTable();

    char name[10];
    strcat(name, "cat");
    strcat(name, " and ");
    printf("strlen = %lu, temp = %s]\n", strlen(name), name);

//    printf("strlen(u1->username) = %lu\n", strlen(u1->username));
//    printf("strcmp(name, u1->username) = %d \n", strcmp(name, u1->username));
//    user_t users[10];
//    int i;
//    for(i=0; i<10; i++) {
//        users[i].sockfd = -1;
//        users[i].username = NULL;
//    }
//    users[8].sockfd = 33;
//    users[8].username = (char*)malloc(sizeof(char)*11);
//    memcpy(users[8].username, name, strlen(name));
//    // strcpy(users[8].username, name);
//    printf("user8: %s\n", users[8].username);
//    int ret = findUserSockByName(users, 10, "Vctor");
//    printf("find ret : %d\n", ret == -1);
    return 0;
}